package com.log.response;

import lombok.Data;

/**
 * 统一返回对象
 *
 * @author zwj
 * @date 2021-04-08
 */
@Data
public class ObjectRestResponse<T> {

    private T data;
    private boolean rel;
    private String msg;

    private void setRel(boolean rel) {
        this.rel = rel;
    }

    private void setData(T data) {
        this.data = data;
    }

    private void setMsg(String msg) {
        this.msg = msg;
    }

    public ObjectRestResponse success(T data, String msg) {
        this.setRel(true);
        this.setMsg(msg);
        this.setData(data);
        return this;
    }

    public ObjectRestResponse success(T data) {
        this.setRel(true);
        this.setMsg("成功");
        this.setData(data);
        return this;
    }

    public ObjectRestResponse success() {
        this.setRel(true);
        this.setMsg("成功");
        this.setData(null);
        return this;
    }

    public ObjectRestResponse error(String msg) {
        this.setRel(false);
        this.setMsg(msg);
        return this;
    }

    public ObjectRestResponse error() {
        this.setRel(false);
        this.setMsg("失败");
        return this;
    }

}
